﻿<%--
 *  File:    VisitPlanMoveSummary.jsp
 *  @Author: ChinaLiu
 *  Date:    2009-10-20
 *
 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.log4j.Category"%>


<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>

<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom"%>


<%
String privilegeCode = "H0255,H0256";
//String privilegeCode = "ALL";
  String strTableName = "v_visitplansummary";
  String strModuleName = "SFE";
	String contextPath = request.getContextPath();
	

  		String ids=(String)request.getParameter("ids");
 		String oldyear= (String)request.getParameter("year");
 		String oldmonth= (String)request.getParameter("monthofyear");
		String oldweek= (String)request.getParameter("weekofmonth");
		String oldday= (String)request.getParameter("dayofweek");
		String oldcontactid= (String)request.getParameter("oldcontactid");
	//	System.out.print("contact------------"+oldcontactid);

%>

<%@ include file="/inc/PageDefault.inc"%>
<%@ include file="/inc/LocationDefault.inc"%>
<html>
	<head>
		<title>VisitPlanMoveSummary</title>
		<%
if("Y".equals(request.getParameter("isconfirm"))){%>

<script>
	parent.opener.refreshWindow();
</script>
<%return;
}%>	
		<PageFlow:CheckPageFlow pageName="p_visitplanmove" />
		<%@ include file="/inc/SumDiv.inc"%>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet"
			href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css"
			type="text/css">
		<script language="JavaScript"
			src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
		<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
		<script language="JavaScript"
			src="<%=contextPath%>/js/SummaryDivision.js"></script>
		<script language="JavaScript">
<%--  put your custom script here   --%>
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "VisitPlanSummary.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}

function page_radiotrue(obj,nyear,nmonth,nweek,nday,ndate)
{
	
	radiotrue(obj);
	var cform = document.cform;
	 cform.chooseyear.value=nyear;
	 cform.choosemonth.value=nmonth;
	 cform.chooseweek.value=nweek;
	 cform.chooseday.value=nday;
	 cform.choosedate.value=ndate;
}	

function page_confirm()
{	
var myform = eval("document.cform");	
	if(<%=ids%>==null||<%=ids%>=="")
	{
	 alert("<%= message.getMessageDesc("MOVE_RECORD_IS_NULL")%>");
		return;
	}
//	alert(cform.chooseyear.value);
//	alert(cform.contactid.value);
	
	if(cform.chooseyear.value==<%=oldyear%>&&cform.choosemonth.value==<%=oldmonth%>&&cform.chooseweek.value==<%=oldweek%>&&cform.chooseday.value==<%=oldday%>&&cform.contactid.value==<%=oldcontactid%>)
 		{
	 alert("<%= message.getMessageDesc("MUST_SELECT_TIME_IS_NOT_SAME")%>");
 		return;
 		}
 		
 		myform.actionname.value = "move";
 		myform.target="_self";
 		isRunning = true;
 		myform.submit();
}


</script>
	</head>

	<body style="overflow: auto;">
		<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
			<input type="hidden" name="pagename" value="p_visitplanmove">
			<input type="hidden" name="actionname">
			<input type="hidden" name="chooseyear">
			<input type="hidden" name="choosemonth">
			<input type="hidden" name="choosedate">
			<input type="hidden" name="chooseweek">
			<input type="hidden" name="chooseday">
			<input type="hidden" name="choosevisitplanid">
			<input type="hidden" name="ids" value="<%=ids %>">
			<%--  page location   --%>


			<table width="100%" cellspacing="0" border="0" cellpadding="0">

				<tr>
					<td>
						<table width="100%" border="1" cellpadding="0"
							bordercolorlight="#999999" bordercolordark="#FFFFFF"
							cellspacing="0" align="center">
							<tr class="deepblue-left">
								<td class="title_center" width="22" >
									&nbsp;
								</td>
								<td class="title_center" width="50" ><%=label.getLabelName("L_weeks")%></td>
								
								<%-- <td class="title_center"  width="80" ><%=label.getLabelName("L_VisitPlanDate")%></td>--%>
								<!--td class="title_center" width="80"><%=label.getLabelName("L_CustomerCode")%></td>
								<td class="title_center"><%=label.getLabelName("L_CustomerName")%></td>
								<td class="title_center" width="80"><%=label.getLabelName("L_OrgPCName")%></td-->
								<td class="title_center"   ><%=label.getLabelName("L_PlanActivityTypeInfo")%></td>
          		
								<td class="title_center" width="120"><%=label.getLabelName("L_ProcessName")%></td>
								<%--  <td class="title_center"  width="80" ><%=label.getLabelName("L_VisitPlanStartTime")%></td>
          		  <td class="title_center"  width="80" ><%=label.getLabelName("L_VisitPlanEndTime")%></td>--%>
							</tr>
									<%
HashMap visitplaninfo=(HashMap)pageContext.getAttribute("visitplaninfo");
Vector vPlans=(Vector)pageContext.getAttribute("visitplandetails");
		if(vPlans==null)
			vPlans=new Vector();
if(visitplaninfo!=null&&visitplaninfo.size()>0){     
Integer defaultvisitplanid=null;
defaultvisitplanid = (Integer)visitplaninfo.get("visitplanid");
Date weekstart=(Date)visitplaninfo.get("weekstart");
java.text.SimpleDateFormat sdf2Str=new java.text.SimpleDateFormat("yyyy-MM-dd");
String sWeekStartDate= sdf2Str.format(weekstart);
weekstart=sdf2Str.parse(sWeekStartDate);	
Calendar calWeekStartDate=Calendar.getInstance();
calWeekStartDate.clear();
calWeekStartDate.setTime(weekstart);
int defaultchooseYear=calWeekStartDate.get(Calendar.YEAR);
int defaultchooseMonth=calWeekStartDate.get(Calendar.MONTH);
defaultchooseMonth=defaultchooseMonth+1;
int defaultchooseDate=calWeekStartDate.get(Calendar.DATE);
int defaultchooseWeek=calWeekStartDate.get(Calendar.WEEK_OF_MONTH);
int defaultchooseDay=calWeekStartDate.get(Calendar.DAY_OF_WEEK);
 %>	<script>
cform.chooseyear.value=<%=defaultchooseYear%>;
cform.choosemonth.value=<%=defaultchooseMonth%>;
cform.choosedate.value=<%=defaultchooseDate%>;
cform.chooseweek.value=<%=defaultchooseWeek%>;
cform.chooseday.value=<%=defaultchooseDay%>;
cform.choosevisitplanid.value=<%=defaultvisitplanid%>;
</script>
							<%
       String[] weekLabelArrs=new String[]{"L_Sunday","L_Monday","L_Tuesday","L_Wednesday","L_Thursday","L_Friday","L_Saturday"};
            for(int index=0; index<7; index++){
            int nYear=0;
			int nMonth=0;
			int nWeek=0;
			int nDay=0;
			int nDate=0;
			nYear=calWeekStartDate.get(Calendar.YEAR);
			nMonth=calWeekStartDate.get(Calendar.MONTH);
			nDate=calWeekStartDate.get(Calendar.DATE);
			nWeek=calWeekStartDate.get(Calendar.WEEK_OF_MONTH);
			nDay=calWeekStartDate.get(Calendar.DAY_OF_WEEK);
              String strClassType = ""; 
              String strIsChecked = "";  
              Integer preday=null;
              HashMap onePlanMap=null;
              Iterator iter=vPlans.iterator();
              int j=0;

              int nWeekGroup=100;
              int nDayCount=0;
              int daynum=index+1;
 
              boolean weekGroup=true;
		//	  boolean dayGroup=false;
  			  boolean firstCount=false;
  			  
              while(iter.hasNext()){	
             	strIsChecked = "";         
				if ( index == 0 ){
			       strIsChecked = "Checked";                       
			    } 

			   if ( j % 2 == 1 )  strClassType = "td-listrom";      
			   else  strClassType = "";
              	onePlanMap=(HashMap)iter.next();
              	pageContext.setAttribute("oneplandetail",onePlanMap);
       
              	if(preday==null){   
              		preday=(Integer)onePlanMap.get("dayofweek");      	
              		nDayCount=1;
                //	dayGroup=true;
            		firstCount=true;
              	}else{
              	//	dayGroup=false;
              	}
              	Integer days =new Integer(daynum);
              	if(days.equals((Integer)onePlanMap.get("dayofweek"))){
              		j++;
              		if(firstCount==true)
              		{
              		nWeekGroup=0;
              		nDayCount=1;
              		}
              		else
              		nDayCount++;
              		weekGroup=false;
              	//	dayGroup=false;
              		firstCount=false;
              		}
              		else{	
              		weekGroup=true;
              		}
            %>
          <%
          if(nWeekGroup==0&&!weekGroup){
          %>

							<tr onMouseOver="this.className='tr-over'"
								onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'"
								 onClick="javascript:page_radiotrue('checkbox<%=JspHelper.filterNull(daynum  )%>','<%=nYear%>','<%=nMonth+1%>' , '<%=nWeek%>','<%=nDay%>','<%=nDate%>')"
								class="<%=JspHelper.filterNull( strClassType )%>">

								<td rowspan="" id="td__checkbox_<%=daynum%>">
									<input type="radio" <%=strIsChecked%>
										id="checkbox<%=JspHelper.filterNull( daynum )%>"
										name="checkid" class="checkbox"
										onClick="javascript:page_radiotrue('checkbox<%=JspHelper.filterNull( daynum )%>','<%=nYear%>','<%=nMonth+1%>' , '<%=nWeek%>','<%=nDay%>','<%=nDate%>')">
								</td>


								<td rowspan="" id="td__week_<%=daynum%>"><%=label.getLabelName(weekLabelArrs[daynum-1])%></td>

					
								<%
					nWeekGroup=150;
					}
				else if(!weekGroup)
				{
				%>
							
							<tr onMouseOver="this.className='tr-over'"
								onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'" onClick="javascript:page_radiotrue('checkbox<%=JspHelper.filterNull(daynum)%>','<%=nYear%>','<%=nMonth+1%>' , '<%=nWeek%>','<%=nDay%>','<%=nDate%>' )"
								class="<%=JspHelper.filterNull( strClassType )%>">
					
								<%
					}if(nDayCount>1){%>

		<script>								
          	td__checkbox_<%=daynum%>.rowSpan=<%=nDayCount%>;
          	td__week_<%=daynum%>.rowSpan=<%=nDayCount%>;
          </script>	
								
					
			<%}if(!weekGroup){ %>
								<!--td>
									<custom:write name="oneplandetail" property="customercode"
										nbsp="true" />
								</td>
								<td>
									<custom:write name="oneplandetail" property="customershortname"
										nbsp="true" />
								</td>
								<td>
									<custom:write name="oneplandetail" property="globalpcname"
										nbsp="true" />
								</td>
								<td>
									<custom:write name="oneplandetail" property="processname"
										nbsp="true" />
								</td-->
						<td>
								<%pageContext.setAttribute("displayflag","view");%>
								<custom:selectdic name="oneplandetail" property="activitytype" dictType="PlanActivityType"  />
           		
							<%
							Integer activityType=(Integer)onePlanMap.get("activitytype");
							
							if(activityType.intValue()==1){
							%>
							
								(
								<a onclick=""><custom:write name="oneplandetail" property="customercode" nbsp="true"/></a>
									&nbsp;
								<custom:write name="oneplandetail" property="customershortname" nbsp="true" />
									&nbsp;
									<custom:selectdic name="oneplandetail" property="globalpccode" dictType="GlobalPCCode"  />
           		
								
									)
									
						
							<%}
							
							%>
								</td>
								<td><custom:select name="oneplandetail"  property="processid"  optionsName="allprocesses" optionValueKey="visitprocessid" optionInnerTextKey="processname"   defaultValue="---" defaultValueCost=" "/></td>
							<%pageContext.setAttribute("displayflag","");%>
							</tr>

							<%}
							}if(nWeekGroup==100){%>
			
							<tr onMouseOver="this.className='tr-over'"
								onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'"
								 onClick="javascript:page_radiotrue('checkbox<%=JspHelper.filterNull(daynum  )%>','<%=nYear%>','<%=nMonth+1%>' , '<%=nWeek%>','<%=nDay%>','<%=nDate%>')"
								class="<%=JspHelper.filterNull( strClassType )%>">

								<td rowspan="" id="td__checkbox_<%=daynum%>">
									<input type="radio" <%=strIsChecked%>
										id="checkbox<%=JspHelper.filterNull( daynum )%>"
										name="checkid" class="checkbox"
										onClick="javascript:page_radiotrue('checkbox<%=JspHelper.filterNull( daynum )%>','<%=nYear%>','<%=nMonth+1%>' , '<%=nWeek%>','<%=nDay%>','<%=nDate%>')">
								</td>


								<td rowspan="" id="td__week_<%=daynum%>"><%=label.getLabelName(weekLabelArrs[daynum-1])%></td>
		<script>			
			<%if(nDayCount==0){		%>	
						td__checkbox_<%=daynum%>.rowSpan=1;
          	td__week_<%=daynum%>.rowSpan=1;
          <%}else{%>
          	td__checkbox_<%=daynum%>.rowSpan=<%=nDayCount%>;
          	td__week_<%=daynum%>.rowSpan=<%=nDayCount%>;
          	<%}%>
          </script>
          	<td>&nbsp;</td>  	<td>&nbsp;</td>  	<!--td>&nbsp;</td>  	<td>&nbsp;</td-->
								</tr>				
							
							<%}
          calWeekStartDate.add(Calendar.DATE,1);  
            }
           %>


						</table>
						<table width="100%" cellspacing="0" cellpadding="0">
							<tr>
								<td class="summary_top"></td>
							</tr>
							<tr>
								<td class="td_center">
								<input type="hidden" name="contactid" value="<%=JspHelper.filterNull(visitplaninfo.get("contactid"))%>">
									<a onclick="page_confirm();"><custom:button type="1"
											label="L_Confirm" imgsrc="new.gif" border="0" style="width:60" />
									</a>

								</td>
							</tr>
						</table>
			<%} %>
					</td>
				</tr>
			</table>

		</form>
	</body>
</html>